<?php

namespace App\Entities;

use App\Support\Database\Eloquent\UuidModel;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Builder;

/**
 * Class Quiz
 * @package App\Entities
 * @method static Builder withOptions()
 */
class ChopHand extends UuidModel
{
    use SoftDeletes;

    const TYPE_CHOICE_SINGLE = 1; // 单选题
    const TYPE_CHOICE_MULTI = 2;  // 多选题
    const TYPE_FILL_BLANK = 3;  // 填空题
    const TYPE_MARK_SCORE = 4; // 评分题
    const TYPE_DROP_DOWN = 5; // 下拉

    protected $fillable = [
        'activity_id',
        'type',
        'title',
        'configurations',
        'validations',
    ];

    protected $casts = [
        'configurations' => 'json',
        'validations' => 'json',
    ];

    public function options()
    {
        return $this->hasMany('App\Entities\ChopHandOption', 'chopHand_id', 'id');
    }

    public function sheets()
    {
        return $this->hasMany(ChopHandSheet::class, 'chopHand_id', 'id');
    }

    /**
     * @param $query Builder
     */
    public function scopeWithOptions($query)
    {
        $query->with(['options' => function ($q) {
            $q->orderBy('sort', 'ASC')->orderBy('created_at', 'ASC');
        }]);
    }
}
